package com.sunmouse.toolkit.fragment.custom;


import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sunmouse.toollib.widget.ChoiceLayout;
import com.sunmouse.toolkit.R;
import com.sunmouse.toolkit.fragment.BaseFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class ChoiceLayoutFragment extends BaseFragment {


    @BindView(R.id.m_choice)
    ChoiceLayout mChoice;
    Unbinder unbinder;
    @BindView(R.id.s_choice)
    ChoiceLayout sChoice;


    private ArrayList<String> mData;
    private ArrayList<String> sData;

    public ChoiceLayoutFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_choice_layout, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }


    @Override
    public void init() {
        this.mData = new ArrayList<>();
        this.sData = new ArrayList<>();
        mChoice.addData(mData);
        sChoice.addData(sData);
        loadingData(1);
    }


    @Override
    public void loadingData(int page) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                String s = "ABCDEFGHIJKL";
                for (int i = 0; i < 8; i++) {
                    mData.add(s.substring(0, (int) (Math.random() * 10) + 1));
                    sData.add("Second-" + (i + 1));
                }

                mHandler.sendEmptyMessage(0);
            }
        }, 2 * 1000);

    }

    @Override
    public void onHandleMessage(Message msg) {
//        super.onHandleMessage(msg);
       this.mChoice.notifyDataChanged();
       this.sChoice.notifyDataChanged();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
